package com.yangrd.helper.crudhelper.core.crud.page.impl;

import com.yangrd.helper.crudhelper.core.crud.page.TranslateService;
import lombok.RequiredArgsConstructor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * description: CacheTranslateService
 *
 * @author: yangrd
 * @date: 2020/9/15
 * @version: 1.0
 */
@RequiredArgsConstructor
public class CacheTranslateService implements TranslateService {

    private final List<TranslateService> translateServices;

    private Map<String,String> english2CNMap = new HashMap<>();

    @Override
    public String translateCN(String english) {
        return  english2CNMap.computeIfAbsent(english, k->translateServices.iterator().next().translateCN(k));
    }
}
